//
//  LHAccount.m
//  OCSinaWeibo
//
//  Created by LiHong on 15/11/2.
//  Copyright © 2015年 LiHong. All rights reserved.
//

#import "LHAccount.h"
static LHAccount *account = nil;
@implementation LHAccount
+ (instancetype)shareAccount{

    if (account == nil) {
        account = [[self alloc]init];
    }
    return account;
}

+ (instancetype)allocWithZone:(struct _NSZone *)zone{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        account = [super allocWithZone:zone];
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        account.access_token = [defaults objectForKey:@"access_token"];
        account.uid = [defaults objectForKey:@"uid"];
        account.expires_in = [defaults objectForKey:@"expires_in"];
        account.avatar_large = [defaults objectForKey:@"avatar_large"];
    });
    return account;
}

- (void)saveAccountToSandBox{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:self.access_token forKey:@"access_token"];
    [defaults setObject:self.uid forKey:@"uid"];
    [defaults setObject:self.expires_in forKey:@"expires_in"];
    [defaults setObject:self.avatar_large forKey:@"avatar_large"];
    [defaults synchronize];
}

- (BOOL)isLogin{
    return self.access_token.length;
}


@end
